<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" label-width="68px">
      <el-form-item label="员工ID" prop="userId">
        <el-input v-model="queryParams.userId"/>
      </el-form-item>
      <el-form-item label="日期">
        <el-date-picker
          v-model="dateRange"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="hrAttendanceList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="员工名称" align="center" prop="empName"/>
      <el-table-column label="当前时间" align="center" prop="cyrrentData">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.cyrrentData, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="开始时间" align="center" prop="checkIn">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.checkIn) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="结束时间" align="center" prop="checkOut">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.checkOut) }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="late" label="是否迟到">
        <template slot-scope="scope">
          <span v-if="scope.row.late" style="color: red;font-weight: bold">是</span>
          <span v-if="!scope.row.late">否</span>
        </template>
      </el-table-column>
      <el-table-column prop="early" label="是否早退">
        <template slot-scope="scope">
          <span v-if="scope.row.early" style="color: red;font-weight: bold">是</span>
          <span v-if="!scope.row.early">否</span>
        </template>
      </el-table-column>
      <el-table-column prop="lackCard" label="是否缺卡">
        <template slot-scope="scope">
          <span v-if="scope.row.lackCard" style="color: red;font-weight: bold">是</span>
          <span v-if="!scope.row.lackCard">否</span>
        </template>
      </el-table-column>
      <el-table-column label="外勤时间" align="center" prop="fieldWork">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.fieldWork) }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="fieldAddress" label="外勤地址"/>
      <el-table-column label="创建时间" align="center" prop="createDate">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createDate) }}</span>
        </template>
      </el-table-column>
      <!--<el-table-column label="操作" align="center" class-name="small-padding fixed-width">-->
        <!--<template slot-scope="scope">-->
          <!--<el-button-->
            <!--size="mini"-->
            <!--type="text"-->
            <!--icon="el-icon-search"-->
            <!--@click="handleShow(scope.row)"-->
          <!--&gt;详情-->
          <!--</el-button>-->
        <!--</template>-->
      <!--</el-table-column>-->
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

  </div>
</template>

<script>
  import { listAttendance } from '@/api/gyy/attendance'

  export default {
    name: 'Attendance',
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 公告表格数据
        hrAttendanceList: [],
        // 日期范围
        dateRange: [],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          userId:null
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {}
      }
    },
    created() {
      this.getList()
    },
    methods: {
      /** 查询列表 */
      getList() {
        this.loading = true
        listAttendance(this.addDateRangeStart(this.queryParams, this.dateRange, 'Date')).then(response => {
          this.hrAttendanceList = response.rows
          this.total = response.total
          this.loading = false
        })
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.getList()
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm('queryForm')
        this.handleQuery()
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.noticeId)
        this.single = selection.length !== 1
        this.multiple = !selection.length
      },
      handleShow(row) {
        const tableId = row.id || 0
        const name = row.title
        this.$tab.openPage('查看[' + name + ']详情', '/gyy/audit-detail/index/' + tableId)
      }
    }
  }
</script>
